package com.djk.daily.thread.threadobjectclasscommonmethods;

import java.util.concurrent.TimeUnit;

/**
 * @Description 演示join，注意语句输出顺序，会变化。
 * @Author dujunkai
 * @Date 2021/7/13 22:13
 **/
public class Join {
    public static void main(String[] args) throws InterruptedException {
        Thread threadA = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + "执行完毕");
            }
        },"线程A");

        Thread threadB = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + "执行完毕");
            }
        }, "线程B");
        threadA.start();
        threadB.start();
        System.out.println("开始等待子线程执行完毕");
        threadA.join();
        threadB.join();
        System.out.println("所有子线程执行完毕");

    }
}
